package com.topscomm.mis.cbb.pm.controller;

import com.topscomm.mis.cbb.pm.api.ITaskEditDocService;
import com.topscomm.mis.cbb.pm.api.ITaskService;
import com.topscomm.mis.cbb.pm.controller.auto.CbbPmTaskControllerAuto;
import com.topscomm.mis.cbb.pm.controller.auto.CbbPmTaskEditDocControllerAuto;
import com.topscomm.pub.util.BaseUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.Page;
import com.topscomm.pub.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Validated
@RestController
@RequestMapping("cbb/pmTaskEditDoc")
public class CbbPmTaskEditDocController extends CbbPmTaskEditDocControllerAuto {
    @Autowired
    private ITaskEditDocService taskEditDocService;

    private String spellListSql(Map<String, Object> paraMap) {
        StringBufferProxy sql = new StringBufferProxy();
        sql.appendSingle(" 1=1 ");
        if (paraMap.containsKey("qry_code")) {
            String value = paraMap.get("qry_code").toString();
            if (!StringUtil.isEmpty(value)) {
                sql.appendSingle(" and code = '{0}' ", value);
            }
        }
        if (paraMap.containsKey("qry_round")) {
            String value = paraMap.get("qry_round").toString();
            if (!StringUtil.isEmpty(value)) {
                sql.appendSingle(" and round = '{0}' ", value);
            }
        }
        return sql.toString();
    }
    /**
     * @description: 新增
     * @param paraMap
     * @return com.topscomm.pub.vo.ResponseResult<java.lang.Object>
     * @author: wangxinhua
     * @date: 2023/6/14 10:35
     * @modify:
     */
    @PostMapping(value = "/insert")
    public ResponseResult<Object> insert(@RequestBody(required = false) Map<String, Object> paraMap) {
        Map<String, Object> resMap = taskEditDocService.insert(paraMap);
        return ResponseResult.ok(resMap);
    }


    /**
     * @description: 修改
     * @param paraMap
     * @return com.topscomm.pub.vo.ResponseResult<java.lang.Object>
     * @author: wangxinhua
     * @date: 2023/6/14 10:35
     * @modify:
     */
    @PutMapping(value = "/update")
    public ResponseResult<Object> update(@RequestBody(required = false) Map<String, Object> paraMap) {
        taskEditDocService.update(paraMap);
        return ResponseResult.ok("修改成功");
    }



    /**
     * @description: 删除
     * @param paraMap
     * @return com.topscomm.pub.vo.ResponseResult<java.lang.Object>
     * @author: wangxinhua
     * @date: 2023/6/14 10:35
     * @modify:
     */
    @DeleteMapping(value = "/delete")
    public ResponseResult<Object> delete(@RequestBody(required = false) Map<String, Object> paraMap) {
        BaseUtil.decodeSecureMap(paraMap);
        taskEditDocService.delete(paraMap);
        return ResponseResult.ok("删除成功");
    }


    /**
     * @description: 加载数据
     * @param paraMap
     * @return com.topscomm.pub.vo.ResponseResult<java.lang.Object>
     * @author: wangxinhua
     * @date: 2023/6/14 10:35
     * @modify:
     */
    @GetMapping(value = "/load")
    public ResponseResult<Object> load(@RequestParam(required = false) Map<String, Object> paraMap) {
        BaseUtil.decodeSecureMap(paraMap);
        Map<String, Object> dataMap = taskEditDocService.load(paraMap);
        return ResponseResult.ok(dataMap);
    }

    /**
     * @description: 查询列表
     * @param paraMap
     * @return com.topscomm.pub.vo.ResponseResult<java.lang.Object>
     * @author: wangxinhua
     * @date: 2023/6/20 14:47
     * @modify:
     */
    @GetMapping(value = "/list")
    public ResponseResult<Object> list(@RequestParam(required = false) Map<String, Object> paraMap) {
        BaseUtil.decodeSecureMap(paraMap);
        String sqlWhere = this.spellListSql(paraMap);
        Page page = taskEditDocService.list(paraMap, sqlWhere);
        return ResponseResult.ok(page);
    }
}
